/**  
 * @Title: GameValidator.java
 * @Package com.limit.control.admin.validate
 * @author maoyun(maoyun0903@163.com)
 * @date 2014-4-4 下午03:51:32
 * @version V1.0
 */ 
package com.limit.control.admin.validate;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;
import com.limit.model.Admin;
import com.limit.model.Game;
import com.limit.model.GameType;
import com.limit.utils.PropertiesUtil;

/** 
 * <br/>
 * @author maoyun(maoyun0903@163.com)
 * @date 2014-4-4 下午03:51:32 
 * @version V1.0
 */

public class GameValidator extends Validator {

	/* 
	 * 
	 * @param c 
	 * @see com.jfinal.validate.Validator#validate(com.jfinal.core.Controller) 
	 */ 
	@Override
	protected void validate(Controller c) {
		c.getFiles(PropertiesUtil.load("game_image_path"));
		this.validateRequired("game.name", "nameError", "游戏名不能为空！");
		this.validateRequired("game.sort_id", "sort_idError", "排序号不能为空！");
		this.validateRequired("game.admin_id", "admin_idError", "关联CP不能为空！");
		this.validateRequired("game.type_id", "type_idError", "关联游戏类型不能为空！");
		this.validateRequired("game.price", "priceError", "价格不能为空！");
		this.validateRequired("game.online_time", "online_timeError", "上线时间不能为空！");
		this.validateRequired("game.version_update", "version_updateError", "版本更新时间不能为空！");
		this.validateRequired("game.version", "versionError", "版本号不能为空！");
		this.validateRequired("game.grade", "gradeError", "游戏评分不能为空！");
//		this.validateRequired("game.ios_path", "ios_pathError", "IOS下载地址不能为空！");
		this.validateRequired("game.description", "descriptionError", "简介不能为空！");
		this.validateRequired("game.detail", "detailError", "详情介绍不能为空！");
	}

	/* 
	 * 
	 * @param c 
	 * @see com.jfinal.validate.Validator#handleError(com.jfinal.core.Controller) 
	 */ 
	@Override
	protected void handleError(Controller c) {
		c.setAttr("admins", Admin.dao.getListExceptAdmin());
		c.setAttr("gametypes", GameType.dao.getList());
		c.keepModel(Game.class);
		c.render("game_view.html");
	}

}
